import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)


const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace;
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err);
}

const routes = [{
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    component: () => import('../views/home/Home.vue')
  },
  {
    path: '/category',
    component: () => import('../views/category/Category.vue')
  },
  {
    path: '/shopcart',
    component: () => import('../views/shopcart/Shopcart.vue')
  },
  {
    path: '/profile',
    component: () => import('../views/profile/Profile.vue')
  },
  { // 详情页
    path: '/detail',
    component: () => import('../views/detail/Detail.vue')
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
